<template>
  <div>
    <el-carousel height="230px">
      <el-carousel-item v-for="item in 3" :key="item">
        <img src="../img/banner1.jpg" alt="" class="banner_img" />
      </el-carousel-item>
    </el-carousel>
    <div class="selector_wrap">
      <div class="select_container">
        <div class="selector_top">
          <span class="select_title">城市:</span>
          <ul class="city_list" ref="cityListRef">
            <li
              class="selector_active"
              style="width: 140px"
              @click="switchCity(country, $event)"
            >
              全国
            </li>
            <li
              v-for="city in cityList"
              :key="city.id"
              @click="switchCity(city, $event)"
            >
              {{ city.name }}
            </li>
            <li class="city_more">
              <span>更多城市</span>
              <svg
                height="5"
                width="12"
                xmlns="http://www.w3.org/2000/svg"
                version="1.1"
                class="category_arrow"
              >
                <path
                  d="M0 0 L5 5 L10 0"
                  stroke-width="1"
                  stroke="#999"
                  fill="none"
                ></path>
              </svg>
            </li>
          </ul>
        </div>
        <div class="selector_middle">
          <span class="select_title">类型:</span>
          <ul class="all_type">
            <li
              :class="typeIndex === index ? 'selector_active' : ''"
              v-for="(_type, index) in typeList"
              :key="_type.key"
              @click="switchType(index)"
            >
              {{ _type.value }}
              {{ _type.project_num > 0 ? `(${_type.project_num})` : "" }}
            </li>
          </ul>
        </div>
        <div class="selector_bottom">
          <span class="select_title">筛选:</span>
          <ul class="all_time">
            <li
              :class="timeIndex === index ? 'selector_active' : ''"
              v-for="(time, index) in timeList"
              :key="time.key"
              @click="switchTime(index)"
            >
              {{ time.value }}
            </li>
          </ul>
        </div>
      </div>
    </div>
    <div class="vipShop_body">
      <div class="vipShop_body_list">
        <div
          v-for="(item, index) in showList"
          :key="item.id"
          @mouseenter="hoverStart(index)"
          @mouseleave="hoverEnd"
          @click="goDetail(item.id)"
          ref="body_list_item_ref"
          class="body_list_item"
          :class="index === hoverIndex ? 'body_list_item_hover' : ''"
        >
          <div
            class="body_item_img"
            :class="index === hoverIndex ? 'body_item_img_hover' : ''"
          >
            <img :src="item.cover" width="100%" alt="" />
          </div>
          <div class="body_item_content">
            <p class="body_item_title">{{ item.project_name }}</p>
            <div>
              <div class="item_content_wrap wrapone">
                <span class="item_content_time"></span>
                <span class="item_content_text">
                  {{ item.start_time }} - {{ item.end_time }}
                </span>
              </div>
              <div class="item_content_wrap wraptwo">
                <span class="item_content_address"></span>
                <span class="item_content_text">{{ item.venue_name }}</span>
              </div>
            </div>
            <div class="body_item_price">
              <span class="item_price_icon">¥</span>
              <span class="item_price">{{ item.price_low / 100 }}</span>
              <span v-show="item.price_low !== item.price_high">起</span>
              <span class="promo_item">{{ item.label }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
    <el-pagination
      class="el-pagination"
      :page-size="pageSize"
      :current-page="currentPage"
      small
      layout="prev, pager, next"
      :total="total"
      @current-change="currentChange"
    >
    </el-pagination>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "VipShopShow",
  data() {
    return {
      hoverIndex: -1,
      cityList: [],
      showList: [],
      typeList: [],
      timeList: [],
      typeIndex: 0,
      timeIndex: 0,
      currentPage: 1,
      pageSize: 16,
      total: 0,

      country: {
        name: "全国",
        id: -1,
      },
      cityId: -1,
    };
  },
  mounted() {
    this.getShowList(1, this.country.id);
    this.getTypeList(this.cityId);
    this.getCityList();
  },
  methods: {
    // 漫展演出hover事件
    hoverStart(index) {
      this.hoverIndex = index;
    },
    hoverEnd() {
      this.hoverIndex = -1;
    },
    // 跳转到详情页
    goDetail(detailId) {
      this.$emit("setIsBtnShow", detailId);
    },

    // 漫展演出
    async getShowList(currentPage, area) {
      // const res = await axios({
      //   url: `/api/ticket/project/listV2?version=134&page=${currentPage}&pagesize=16&area=${area}&filter=&platform=web&p_type=%E5%85%A8%E9%83%A8%E7%B1%BB%E5%9E%8B`,
      //   method: "get",
      // });
      await this.$store.dispatch("getShowListApi", { currentPage, area });
      this.showList = this.$store.state.showList;
      this.total = this.$store.state.total;
    },

    // 获取城市列表
    async getCityList() {
      const res = await axios({
        url: `/api/ticket/city/list?channel=4`,
        method: "get",
      });
      this.cityList = res.data.data.list;
    },
    // 获取类型类型
    async getTypeList(id) {
      const res = await axios({
        url: `/api/ticket/project/listconf?city_id=${id}&platform=pc`,
        method: "get",
      });

      this.typeList = res.data.data.tags;

      // 获取筛选数组
      this.timeList = res.data.data.filter;
    },
    // 切换类型
    switchType(index) {
      this.typeIndex = index;
    },
    switchTime(index) {
      this.timeIndex = index;
    },
    // 分页器
    currentChange(e) {
      this.getShowList(e, this.cityId);
    },
    // 按钮切换
    switchShow() {
      this.isBtnShow = !this.isBtnShow;
    },
    // 城市切换
    async switchCity(item, e) {
      await this.getShowList(1, item.id);
      await this.getTypeList(item.id);
      this.currentPage = 1;
      this.cityId = item.id;
      const city = e.path[0].innerText;
      const ul = this.$refs.cityListRef;
      const lis = ul.children;
      for (let i = 0; i < lis.length; i++) {
        lis[i].className = "";
        if (lis[i].innerText === city) {
          lis[i].className += "selector_active";
        }
      }
    },
  },
};
</script>

<style lang="less" scoped>
/* ******************轮播图******************* */

.el-carousel__item img {
  color: #475669;
  opacity: 0.75;
  line-height: 150px;
  margin: 0;
  text-align: center;
  cursor: pointer;
}

.banner_img {
  height: 100%;
}

/* **************************************** */

/* ******************分页器******************* */
::v-deep .el-pagination--small {
  width: 200px;
  margin: 0 auto;
  margin-top: 20px;
}
::v-deep .el-pagination--small,
.btn-prev,
.el-pager,
.btn-next {
  background-color: #f4f5f7;
}
/* **************************************** */

/*********************************** selector **********************************/

.selector_wrap {
  width: 100%;
  box-shadow: 0 0 15px 0 hsl(203deg 6% 45% / 9%),
    0 1px 0 0 rgb(204 208 215 / 30%);
  // z-index: 10;
  background-color: #fff;
}
.select_container {
  width: 1160px;
  margin: 0 auto;
  position: relative;
}

.select_container li:hover {
  color: #f25d8e;
}
.selector_top {
  display: flex;
  height: 40px;
  line-height: 40px;
  border-bottom: 1px dashed #e5e9ef;
  box-sizing: border-box;
}
.city_list .whole_country {
  width: 140px;
}
.select_title {
  width: 90px;
  font-size: 12px;
  color: #99a2aa;
}
.city_list {
  display: flex;
}
.city_list > li {
  cursor: pointer;
  width: 90px;
  color: #6d757a;
}
.city_more {
  text-align: right;
  position: absolute;
  right: 0;
}
.city_more > span {
  margin-right: 8px;
}
.selector_middle {
  display: flex;
  height: 40px;
  line-height: 40px;
  border-bottom: 1px dashed #e5e9ef;
  box-sizing: border-box;
}
.selector_bottom {
  display: flex;
  height: 40px;
  line-height: 40px;
}
.all_type {
  display: flex;
}
.all_type > li {
  width: 140px;
  cursor: pointer;
  color: #6d757a;
}
.all_time {
  display: flex;
}
.all_time > li {
  width: 140px;
  cursor: pointer;
  color: #6d757a;
}
.selector_active {
  color: #f25d8e !important;
}

/*********************************** body开始 ***********************************/
.vipShop_body {
  width: 100%;
  min-height: 1200px;
}
.vipShop_body_list {
  margin: 0 auto;
  width: 1160px;
}
.body_list_item {
  width: 560px;
  height: 237px;
  margin-top: 60px;
  cursor: pointer;
  background-color: #fff;
  border-radius: 8px;
  display: flex;
  position: relative;
  box-shadow: 0 0 15px 0 hsl(203deg 6% 45% / 9%);
  border-radius: 8px;
}
.body_list_item_hover {
  box-shadow: 0 15px 20px 0 hsl(203deg 6% 45% / 40%);
}
.body_item_img {
  position: absolute;
  bottom: 25px;
  left: 20px;
  width: 175px;
  height: 233px;
  box-shadow: 3px 3px 2px 0 hsl(203deg 6% 45% / 30%);
  border-radius: 8px;
  background-size: 100%;
  transition: bottom 0.1s;
  overflow: hidden;
}
.body_item_img_hover {
  bottom: 35px;
  transition: bottom 0.1s;
}

.body_item_content {
  margin-left: 223px;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
}
.body_item_title {
  margin-top: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 290px;
  height: 50px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  font-size: 18px;
  // margin-top: 30px;
}
.item_content_wrap {
  // margin-bottom: 5px;
  display: flex;
  align-items: center;
}
.wrapone {
  margin-bottom: 5px;
}
.wraptwo {
  padding-top: 5px;
}
.item_content_text {
  color: #999;
  font-size: 14px;
}
.item_content_time {
  background-image: url("../img/time.png");
  width: 12px;
  height: 13px;
  margin-right: 8px;
  background-size: 100%;
}
.item_content_address {
  background-image: url("../img/address.png");
  width: 12px;
  height: 13px;
  margin-right: 8px;
  background-size: 100%;
}
.item_price_icon {
  font-size: 18px;
  line-height: 18px;
  color: #f25d8e;
}
.item_price {
  font-size: 28px;
  color: #f25d8e;
  margin-right: 5px;
  margin-left: 3px;
}
.body_item_price {
  margin-bottom: 7px;
}
.vipShop_body_list {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}
.promo_item {
  display: inline-block;
  max-width: 80px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  width: auto;
  height: 16px;
  line-height: 16px;
  margin-left: 8px;
  color: #fb7299;
  font-size: 12px;
  text-align: center;
  border: 1px solid #fb7299;
  border-radius: 1px;
}
</style>
